/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package query;
import graph.*;
/**
 *
 * @author Gonzalo
 */
public class DML{

    private String action=null;
    private String label=null;
    private String value=null;
    private long node1=0;
    private long node2=0;

    public DML(String _action,String _label){ //new node
        action=_action;
        label=_label;
    }
    public DML(String _action,String _label,long n1,long n2){ // new edge(n1,n2)
        action=_action;
        label=_label;
        node1=n1;
        node2=n2;
    }
    public DML(String _action,String _label,String _value,long n1){ // set label=value node
        action=_action;
        label=_label;
        value=_value;
        node1=n1;
    }


    public boolean isNew(){
        return action.compareTo("new")==0;
    }
    public boolean isSet(){
        return action.compareTo("set")==0;
    }
    public boolean isDel(){
        return action.compareTo("del")==0;
    }
    public boolean isNode(){
        return label.compareTo("node")==0;
    }
    public Nodes ejecutar(Graph g){
        Nodes out=new Nodes();
        if(isNew()){
            if(isNode())
                out.add(g.newNode());
            else{
                if(g.addEdge(label, node1, node2)){
                    out.add(node1);
                    out.add(node2);
                }
            }
        } else if(isSet()){
            if(g.setAttribute(node1, label, value))
                out.add(node1);
        }
        g.flush();
        return out;
    }


    public String print(){
        String out=action+" "+label;
        if(value!=null)
            out=out+" "+value;
        if(node1!=0)
            out=out+" "+node1;
        if(node2!=0)
            out=out+" "+node2;
        return out;
    }

}
